﻿@{
    ViewBag.Title = "员工管理";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@section HeadIncluder 
{
     <link href='@Url.Content("~/Content/public.css")' rel="stylesheet" />
    <link href='@Url.Content("~/Content/con_style.css")' rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href=@Url.Content("~/Scripts/skins/default.css")   />
}
 
<div id="bar_btn" class="mb10  clearfix" style="width: 100%; height: 36px;">
    关键字：<input type="text" id="txtkeyword" style="height:25px" name="keyword" />
    <span class="btn_s3 btn_c1"><a id="btnQuery" href="javascript:;" onclick="onRefresh()">查找</a></span>
    <div class="bar_btn f_btnc">
        @if (User.HasFlag(FB.Security.FOA.CompanyManagement.Employee.Create)){<button id="btnAdd" type="button" onclick="add()" class="fj btn_c3 btn_s" >添加</button>}
        @if (User.HasFlag(FB.Security.FOA.CompanyManagement.Employee.Modify)){<button id="btnModify" type="button" onclick="edit()" class="fj btn_c3 btn_s"  >修改</button>}
        @if (User.HasFlag(FB.Security.FOA.CompanyManagement.Employee.Delete)){<button id="btnDelete" type="button" onclick="del()" class="fj btn_c3 btn_s" >删除</button>}
        <button id="btnRefresh" type="button" onclick="onRefresh()" class="fj btn_c3 btn_s" >刷新</button>
        
    </div>
</div>
<div id="container" style="margin-right:10px;"> 
    <div id="grid"  style="width:100%;height:100%;" >
    </div>
</div>
 <script type="text/javascript" src='@Url.Content("~/Scripts/lhgdialog.min.js")'> </script> 
<script type="text/javascript">
    function add() {
        var url = '@Url.Action("Create", "Employee")';
        OpenPop(url, "员工添加", 1050, 620);
    }
    function GetDepartmentList() {
        var url = '@Url.Action("GetDeparmentList", "Team")' + '?CompanyID=' + $("#CompanyList").val();
         $.post(url, function (data) {
             $("#deptConatainer").html(data);
             $("#deparmentList option:first").remove();
         });
     }
    function edit() {
        var grid = $("#grid").data("kendoGrid");
        var items = grid.select();
        if (items.length == 0) {
            $.dialog.alert("请选择要编辑的记录！");
            return;
        }
        if (items.length > 1) {
            $.dialog.alert("只能选择一条记录");
            return;
        }
        var id = items[0].cells[0].textContent;
        var url = '@Url.Action("Create", "Employee")' + "?id=" + id;
        OpenPop(url, "员工编辑", 1050, 700);
    }
    
function del() {
    var url = '@Url.Action("Delete", "Employee")';
        var grid = $("#grid").data("kendoGrid");
        var items = grid.select();
        if (items.length == 0) {
            $.dialog.alert("请选择要删除的记录！");
            return;
        }
        $.dialog.confirm('你确定要删除这个员工吗？', function () {
            var rpValue = "";
            for (var i = 0; i < items.length; i++) {
                var id = items[i].cells[0].textContent;
                rpValue = rpValue + id + ",";
            }
            $.post(url, { rpValue: rpValue }, function (data) {
                onRefresh();
            });
        }, function () {
        });
    }
    function search() {
    }
    function loadData() {
        $("#grid").kendoGrid({
            selectable: "multiple,row",
            dataSource: {
                serverPaging: true,
                serverSorting: true,
                pageSize: 10,
                transport: {
                    read: {
                        url: '@Url.Action("Index")',
                        type: "POST",
                        dataType: "json",
                        data: {
                            keyword: function () {
                                return $("#txtkeyword").val();
                            }
                        }
                    }
                },
                schema: {
                    //取出資料陣列
                    data: function (d) { return d.Data; },
                    //取出資料總筆數(計算頁數用)
                    total: function (d) { return d.TotalCount; }
                }
            },
            height: 600,
           
            pageable: {
                refresh: true,
                pageSizes: true
            },
            sortable: true,
            dataBinding: function (e) {
                for (var i = 0; i < e.items.length; i++) {
                    if (e.items[i].Gender == "W")
                        e.items[i].Gender = "女";
                    else
                        e.items[i].Gender = "男"; 
                }
            },
            pageable: {
                refresh: true,
                pageSizes: true
            },
            columns: [
                { field: "EMPCode", title: "系统编号" },
                { field: "RefCode", title: "员工编号" },
                { field: "ChineseName", title: "姓名" },
                { field: "Gender", title: "性别" },
                { field: "EMPTypeName", title: "员工类型" },
                { field: "Email", title: "Email" },
                { field: "Mobile", title: "联系电话" },
                { field: "ExtensionNo", title: "内部电话" },
                {
                    field: "TerminationDate",
                    title: "入职时间",
                    type:"date",
                    format: "{0:yyyy-MM-dd}"
                }
            ]
        });
    }
    function onRefresh() {
        var grid = $("#grid").data("kendoGrid");
        grid.dataSource.read();
    }
    $(document).ready(function () {
        loadData();
        $("#divTree").kendoTreeView();
    });
    function OpenPop(url, titleName, width, height) {
        width = width || 370;
        height = height || 300;
        window.top.winObj = window;
        window.top.refresh = onRefresh;
        window.top.oDG = $.dialog({
            lock: true,
            background: '#FFF',
            opacity: 0.5,
            id: 'esDialog',
            title: titleName,
            titleAlign: 'left',
            content: "url:" + url,
            width: width,
            height: height,
            btnBar: false,
            lockScroll: true
        });
    }
</script>


